package form;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import trangchu.UtilDelegate;

public class DSJ_KhachHang {
	public String MaKH;
	public String HoTenKH;
	public String DiaChi;
	public String DienThoai;
	public String Fax;
	public String Email;
	public String SoTaiKhoan;
	public String TenNH;
	public String MaNH;
	

	public String getMaNH() {
		return MaNH;
	}
	public void setMaNH(String maNH) {
		MaNH = maNH;
	}
	public String getMaKH() {
		return MaKH;
	}
	public void setMaKH(String maKH) {
		MaKH = maKH;
	}
	public String getHoTenKH() {
		return HoTenKH;
	}
	public void setHoTenKH(String hoTenKH) {
		HoTenKH = hoTenKH;
	}
	public String getDiaChi() {
		return DiaChi;
	}
	public void setDiaChi(String diaChi) {
		DiaChi = diaChi;
	}
	public String getDienThoai() {
		return DienThoai;
	}
	public void setDienThoai(String dienThoai) {
		DienThoai = dienThoai;
	}
	public String getFax() {
		return Fax;
	}
	public void setFax(String fax) {
		Fax = fax;
	}
	public String getEmail() {
		return Email;
	}
	public void setEmail(String email) {
		Email = email;
	}
	public String getSoTaiKhoan() {
		return SoTaiKhoan;
	}
	public void setSoTaiKhoan(String soTaiKhoan) {
		SoTaiKhoan = soTaiKhoan;
	}
	
	public String getTenNH() {
		return TenNH;
	}
	public void setTenNH(String tenNH) {
		TenNH = tenNH;
	}
	public Vector<DSJ_KhachHang> getUsers(){
		Vector list = new Vector();;
		Connection con =UtilDelegate.getConnection();		
		PreparedStatement st;
		try {
			st = con.prepareStatement("select * from KhachHang  join CacNganHang on KhachHang.NganHang = CacNganHang.MaNH ");
			ResultSet rs = st.executeQuery();
			while(rs.next()){
				
				
				String MaKH = rs.getString("MaKH");
				String HoTenKH = rs.getString("HoTenKH");
				String DiaChi = rs.getString("DiaChi");
				String DienThoai = rs.getString("DienThoai");
				String Fax = rs.getString("Fax");
				String Email = rs.getString("Email");
				String SoTaiKhoan = rs.getString("SoTaiKhoan");
				String TenNH = rs.getString("TenNH");
				
				DSJ_KhachHang b = new DSJ_KhachHang();
				b.setMaKH(MaKH);
				b.setHoTenKH(HoTenKH);
				b.setDiaChi(DiaChi);
				b.setDienThoai(DienThoai);
				b.setFax(Fax);
				b.setEmail(Email);
				b.setSoTaiKhoan(SoTaiKhoan);
				b.setTenNH(TenNH);
				list.add(b);
				
								
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list;
	}
	

	public Vector<DSJ_KhachHang> getbank(){
		Vector<DSJ_KhachHang> list2 = new Vector<DSJ_KhachHang>();
		Connection con =UtilDelegate.getConnection();		
		PreparedStatement st;
		try {
			st = con.prepareStatement("select * from CacNganHang");
			ResultSet rs = st.executeQuery();
			while(rs.next()){
				
				String maNH= rs.getString("MaNH");
				String tenNH = rs.getString("TenNH");
				
				DSJ_KhachHang b = new DSJ_KhachHang();
				b.setMaNH(maNH);
				b.setTenNH(tenNH);
				
				list2.add(b);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list2;
	}

	public static void insertInto(DSJ_KhachHang ikhachhang){
		Connection con =UtilDelegate.getConnection();
		try {
			Statement st = con.createStatement();
			String str ="insert into KhachHang(HoTenKH,DiaChi,DienThoai,Fax,Email,SoTaiKhoan,NganHang) values (N'"+ikhachhang.getHoTenKH()+"',N'"+ikhachhang.getDiaChi()+"','"+ikhachhang.getDienThoai()+"','"+ikhachhang.getFax()+"',N'"+ikhachhang.getEmail()+"','"+ikhachhang.getSoTaiKhoan()+"','"+ikhachhang.getTenNH()+"')";			
			st.execute(str);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			UtilDelegate.closeConnection(con);
		}
	}
}
